cmake_minimum_required(VERSION 3.0)
project(sylar)

include(cmake/utils.cmake)

# Wno-builtin-macro-redefined:
# 这个选项显式地禁止将内置宏重新定义的警告
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -fPIC -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations -Wno-unused-result ")
set(CMAKE_C_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -fPIC -ggdb -std=c11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations -Wno-unused-result ")
# -fsanitize=address
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(.)
include_directories(/usr/include)

find_package(Boost REQUIRED)
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
    message(${Boost_INCLUDE_DIRS})
endif()


link_directories(/usr/lib)
link_directories(/usr/lib64)

set(LIB_SRC 
    sylar/log.cpp
    sylar/util.cpp
    sylar/config.cpp
    sylar/thread.cpp
    sylar/fiber.cpp
    sylar/scheduler.cpp
    sylar/iomanger.cpp
    sylar/timer.cpp
    sylar/hook.cpp
    sylar/fd_manager.cpp
)

add_library(sylar SHARED ${LIB_SRC})

force_redefine_file_macro_for_sources(sylar)

set(LIBS 
    sylar
    yaml-cpp
    pthread
    dl
)

add_executable(test_log tests/test_log.cpp)
target_link_libraries(test_log ${LIBS})
force_redefine_file_macro_for_sources(test_log)

add_executable(test_config tests/test_config.cpp)
target_link_libraries(test_config ${LIBS})
force_redefine_file_macro_for_sources(test_config)

add_executable(test_thread tests/test_thread.cpp)
target_link_libraries(test_thread ${LIBS})
force_redefine_file_macro_for_sources(test_thread)


add_executable(test_util tests/test_util.cpp)
target_link_libraries(test_util ${LIBS})
force_redefine_file_macro_for_sources(test_util)

add_executable(test_fiber tests/test_fiber.cpp)
target_link_libraries(test_fiber ${LIBS})
force_redefine_file_macro_for_sources(test_fiber)

add_executable(test_scheduler tests/test_scheduler.cpp)
target_link_libraries(test_scheduler ${LIBS})
force_redefine_file_macro_for_sources(test_scheduler)

add_executable(test_iomanger tests/test_iomanger.cpp)
target_link_libraries(test_iomanger ${LIBS})
force_redefine_file_macro_for_sources(test_iomanger)

add_executable(test_hook tests/test_hook.cpp)
target_link_libraries(test_hook ${LIBS})
force_redefine_file_macro_for_sources(test_hook)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)